﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using System.Globalization;
using Shpm.App.Commons.Utils;

public partial class App_Input_PhysicalSearchForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSourceID = null;
            
            txtPersonId.Text=(string)Context.Items["TXT_PERSONID"]  ;
            txtName.Text=(string)Context.Items["TXT_NAME"]  ;
            txtDate.Text=(string)Context.Items["TXT_DATE"]  ;
            txtEndDate.Text = (string)Context.Items["TXT_END_DATE"];
            //if (Context.Items["LST_LOAD"]!=null && (bool)Context.Items["LST_LOAD"]) GridView1.DataSourceID = this.ObjectDataSource1.ID;
            GridView1.DataSourceID = this.ObjectDataSource1.ID;
            if (Context.Items.Contains("ParamPageIndex"))
            {
                this.ViewState["ParamPageIndex"] = Convert.ToString(this.Context.Items["ParamPageIndex"]);
                this.GridView1.PageIndex = Convert.ToInt32(this.ViewState["ParamPageIndex"]);
            }
       
        }
        
    }
    void Page_PreRender(object sender, EventArgs e)
    {

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PhyscalDao Dao = new PhyscalDao();
        GridView1.DataSourceID = null;
        if (ComValidator1.DoValidator())
        {
            GridView1.DataSourceID = this.ObjectDataSource1.ID;
        }
        this.GridView1.PageIndex=0;
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = GridView1.SelectedRow;
        Context.Items["PERSON_ID"] = row.Cells[0].Text;
        SetContext();
        // Server.Transfer("PhysicalRegisteForm.aspx");
        ControllerUtils.Transfer(Context, "~/App/Input/PhysicalPersonSearchForm.aspx");
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        SetContext();
        // Server.Transfer("PhysicalUpdateForm.aspx");
        ControllerUtils.Transfer(Context, "~/App/Input/PhysicalUpdateForm.aspx");
    }

    private void SetContext()
    {
        //if (GridView1.DataSourceID != null) Context.Items["LST_LOAD"] = true;
        //else Context.Items["LST_LOAD"] = false;
        
        Context.Items["TXT_PERSONID"] = txtPersonId.Text;
        Context.Items["TXT_NAME"] = txtName.Text;
        Context.Items["TXT_DATE"] = txtDate.Text;
        Context.Items["TXT_END_DATE"] = txtEndDate.Text;
        Context.Items["ParamPageIndex"] = Convert.ToString(GridView1.PageIndex);
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //翻页
        GridView1.PageIndex = e.NewPageIndex;
    }
}
